/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cadi.levelsManager;

import com.cadi.aux.Coin;
import com.cadi.aux.CounterEasy;
import com.cadi.menu.MainMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

/**
 *
 * @author ApoZuniga
 */
public class LevelsCountEasy extends CounterEasy {
    private JLabel background;
    public LevelsCountEasy() {
        super();
        voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/cuentas1.wav"));
        voice.play();
        currentLevel = 1;
        toMenu.setVisible(true);
        
        listenerGood = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                totalActionPerformed(ae, 1);
                changeLevel();
            }
        };
        
        listenerBad = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                totalActionPerformed(ae, 0);
            }
        };
        
        coinOne = new Coin(1, "small");
        coinOne.setBounds(300, 250, 75, 75);
        container.add(coinOne, JLayeredPane.PALETTE_LAYER);
        coinTwo = new Coin(1, "small");
        coinTwo.setBounds(450, 250, 75, 75);
        container.add(coinTwo, JLayeredPane.PALETTE_LAYER);
        coinThree = new Coin(1, "small");
        coinThree.setBounds(600, 250, 75, 75);
        container.add(coinThree, JLayeredPane.PALETTE_LAYER);
        coinFour = new Coin(1, "small");
        coinFour.setBounds(750, 250, 75, 75);
        container.add(coinFour, JLayeredPane.PALETTE_LAYER);
        coinFive = new Coin(1, "small");
        coinFive.setBounds(900, 250, 75, 75);
        container.add(coinFive, JLayeredPane.PALETTE_LAYER);
        
        optionTotalOne = new JButton(new ImageIcon(getClass().getResource("/resources/seis.png")));
        optionTotalOne.setBounds(300, 400, 120, 120);
        optionTotalOne.addActionListener(listenerBad);
        container.add(optionTotalOne, JLayeredPane.PALETTE_LAYER);
        
        optionTotalTwo = new JButton(new ImageIcon(getClass().getResource("/resources/cinco.png")));
        optionTotalTwo.setBounds(600, 400, 120, 120);
        optionTotalTwo.addActionListener(listenerGood);
        container.add(optionTotalTwo, JLayeredPane.PALETTE_LAYER);
        
        optionTotalThree = new JButton(new ImageIcon(getClass().getResource("/resources/cuatro.png")));
        optionTotalThree.setBounds(900, 400, 120, 120);
        optionTotalThree.addActionListener(listenerBad);
        container.add(optionTotalThree, JLayeredPane.PALETTE_LAYER);
        background = new JLabel(new ImageIcon(getClass().getResource("/resources/fondo5.png")));
        background.setBounds(0, 0, 1280,800);
        container.add(background, JLayeredPane.PALETTE_LAYER);
        this.window.setVisible(true);
    }
    
    private void setLevelTwo() {
        coinOne.changeIcon(1);
        coinOne.setBounds(300, 250, 75, 75);
        coinTwo.changeIcon(2);
        coinTwo.setBounds(500, 250, 75, 75);
        coinThree.changeIcon(1);
        coinThree.setBounds(700, 250, 75, 75);
        coinFour.setVisible(false);
        coinFive.setVisible(false);
        optionTotalTwo.removeActionListener(listenerGood);
        optionTotalTwo.addActionListener(listenerBad);
        optionTotalThree.removeActionListener(listenerBad);
        optionTotalThree.addActionListener(listenerGood);
        window.repaint();
        voice.play();
    }
    
    private void setLevelThree() {
        coinOne.changeIcon(1);
        coinOne.setBounds(300, 250, 75, 75);
        coinTwo.changeIcon(2);
        coinTwo.setBounds(475, 250, 75, 75);
        coinThree.changeIcon(2);
        coinThree.setBounds(650, 250, 75, 75);
        coinFour.changeIcon(1);
        coinFour.setBounds(825, 250, 75, 75);
       coinFour.setVisible(true);
        optionTotalOne.removeActionListener(listenerBad);
        optionTotalOne.addActionListener(listenerGood);
        optionTotalThree.removeActionListener(listenerGood);
        optionTotalThree.addActionListener(listenerBad);
        
        window.repaint();
        voice.play();
    }
    
    private void setLevelFour() {
        coinOne.changeIcon(0);
        coinOne.setBounds(300, 250, 75, 75);
        coinTwo.changeIcon(1);
        coinTwo.setBounds(450, 250, 75, 75);
        coinThree.changeIcon(0);
        coinThree.setBounds(600, 250, 75, 75);
        coinFour.changeIcon(2);
        coinFour.setBounds(750, 250, 75, 75);
        coinFive.changeIcon(1);
        coinFive.setBounds(900, 250, 75, 75);
        coinFive.setVisible(true);
        optionTotalOne.removeActionListener(listenerGood);
        optionTotalOne.addActionListener(listenerBad);
        optionTotalTwo.removeActionListener(listenerBad);
        optionTotalTwo.addActionListener(listenerGood);
        window.repaint();
        voice.play();
    }
    
    private void setLevelFive() {
        coinOne.changeIcon(0);
        coinOne.setBounds(300, 250, 75, 75);
        coinTwo.changeIcon(1);
        coinTwo.setBounds(450, 250, 75, 75);
        coinThree.changeIcon(0);
        coinThree.setBounds(600, 250, 75, 75);
        coinFour.changeIcon(0);
        coinFour.setBounds(750, 250, 75, 75);
        coinFive.changeIcon(0);
        coinFive.setBounds(900, 250, 75, 75);
        optionTotalOne.setIcon(new ImageIcon(getClass().getResource("/resources/tres.png")));
        optionTotalTwo.removeActionListener(listenerGood);
        optionTotalTwo.addActionListener(listenerBad);
        optionTotalOne.removeActionListener(listenerBad);
        optionTotalOne.addActionListener(listenerGood);
        window.repaint();
        voice.play();
    }
    
    private void changeLevel() {
        switch(currentLevel){
            case 1:
                setLevelTwo();
                currentLevel++;
                break;
            case 2:
                setLevelThree();
                currentLevel++;
                break;
            case 3:
                setLevelFour();
                currentLevel++;
                break;
            case 4:
                setLevelFive();
                currentLevel++;
                break;
            case 5:
                MainMenu main = new MainMenu();
                window.setVisible(false);
                break;
        }
    }
}
